home *** CD-ROM | disk | FTP | other *** search
- Q29471 Bad Code Generated with /Od and Ternary Operator
- C Compiler
- 5.00 5.10 | 5.10
- MS-DOS | OS/2
-
- Summary:
- If the compiler generates incorrect code for evaluating ternary
- operators with optimization disabled, using /Ox corrects the problem.
- This problem was limited to a very special case (described below)
- in which a while() statement makes calls to the toupper() macro using
- a register variable.
- Microsoft has confirmed this to be a problem in Versions 5.00 and
- 5.10. We are researching this problem and will post new information as
- it becomes available.
-
- More Information:
- When compiled with /Od, the code is bad; when compiled with /Ox,
- the code is good.
- The problem lies with the while() statement in function foo(). The
- problem only occurs if foo() has one register parameter.
- If neither or both parameters are register variables, the problem
- ends. The problem also is dependent on having the two calls to
- toupper() and the && with ptr1[i]. (This is a very special-case
- problem.)
- The following is a code demonstration of the problem:
-
- #include <ctype.h>
- #include <stdio.h>
-
- char one[] = "SKIP";
- char two[] = "SKIP";
-
- void foo(char *ptr1, char **ptr2);
- void main(void);
-
- void main(void)
- {
- char *ptr1 = one;
- char *ptr2 = two;
- foo(ptr1, &ptr2);
-
- }
-
- void foo(char *ptr1, char register **ptr2) /* register is needed */
- { /* to force problem */
- int i = 0;
-
- /* here is the problem line... */
- while((toupper(ptr1[i]) == toupper((*ptr2)[i])) && ptr1[i])
- i++;
-
- if (i == 0)
- printf("i is %d; bad code!\n", i);
- else
- printf("good code.\n");
-
- }
-
-
-
- Keywords: buglist5.00 buglist5.10
- Updated 88/07/29 14:28
-